home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / BNU22SR1.ZIP / src / binutils.2 / bfd / coff-i96.c < prev    next >
C/C++ Source or Header  |  1993-05-30  |  7KB  |  215 lines

  1. /* BFD back-end for Intel 960 COFF files.
  2.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #define I960 1
  22. #define BADMAG(x) I960BADMAG(x)
  23.  
  24. #include "bfd.h"
  25. #include "sysdep.h"
  26. #include "libbfd.h"
  27. #include "obstack.h"
  28. #include "coff/i960.h"
  29. #include "coff/internal.h"
  30. #include "libcoff.h"        /* to allow easier abstraction-breaking */
  31. #define COFF_LONG_FILENAMES
  32.  
  33. #define CALLS     0x66003800    /* Template for 'calls' instruction    */
  34. #define BAL     0x0b000000    /* Template for 'bal' instruction    */
  35. #define BAL_MASK 0x00ffffff
  36.  
  37. static bfd_reloc_status_type 
  38. DEFUN (optcall_callback, (abfd, reloc_entry, symbol_in, data,
  39.               ignore_input_section, ignore_bfd),
  40.        bfd *abfd AND
  41.        arelent *reloc_entry AND
  42.        asymbol *symbol_in AND
  43.        PTR data AND
  44.        asection *ignore_input_section AND
  45.        bfd *ignore_bfd)
  46. {
  47.   /* This item has already been relocated correctly, but we may be
  48.    * able to patch in yet better code - done by digging out the
  49.    * correct info on this symbol */
  50.   bfd_reloc_status_type result;
  51.   coff_symbol_type *cs = coffsymbol(symbol_in);
  52.  
  53.   /* So the target symbol has to be of coff type, and the symbol 
  54.      has to have the correct native information within it */
  55.   if ((bfd_asymbol_flavour(&cs->symbol) != bfd_target_coff_flavour)
  56.       || (cs->native == (combined_entry_type *)NULL)) {
  57.      /* This is interesting, consider the case where we're outputting */
  58.      /* coff from a mix n match input, linking from coff to a symbol */
  59.      /* defined in a bout file will cause this match to be true. Should */
  60.      /* I complain ? - This will only work if the bout symbol is non */
  61.      /* leaf. */
  62.      result = bfd_reloc_dangerous;
  63.   }
  64.   else  {
  65.     switch (cs->native->u.syment.n_sclass) 
  66.       {
  67.       case C_LEAFSTAT:
  68.       case C_LEAFEXT:
  69.       /* This is a call to a leaf procedure, replace instruction with a bal
  70.      to the correct location */
  71.     {
  72.       union internal_auxent *aux = &((cs->native+2)->u.auxent);
  73.       int word = bfd_get_32(abfd, (bfd_byte *)data + reloc_entry->address);
  74.       int olf = (aux->x_bal.x_balntry - cs->native->u.syment.n_value);
  75.       BFD_ASSERT(cs->native->u.syment.n_numaux==2);
  76.       /* We replace the original call instruction with a bal to */
  77.       /* the bal entry point - the offset of which is described in the */
  78.       /* 2nd auxent of the original symbol. We keep the native sym and */
  79.       /* auxents untouched, so the delta between the two is the */
  80.       /* offset of the bal entry point */
  81.  
  82.       word = ((word +  olf)  & BAL_MASK) | BAL;
  83.         bfd_put_32(abfd, word, (bfd_byte *) data + reloc_entry->address);
  84.       }
  85.     result = bfd_reloc_ok;
  86.     break;
  87.       case C_SCALL:
  88.     /* This is a call to a system call, replace with a calls to # */
  89.     BFD_ASSERT(0);
  90.     result = bfd_reloc_ok;
  91.     break;
  92.       default:
  93.     result = bfd_reloc_ok;
  94.     break;
  95.       }
  96.   }
  97.   return result;
  98. }
  99.  
  100. static reloc_howto_type howto_rellong =
  101.   { (unsigned int) R_RELLONG, 0, 2, 32,false, 0, true, true,
  102.       0,"rellong", true, 0xffffffff, 0xffffffff};
  103. static reloc_howto_type howto_iprmed =
  104.   {  R_IPRMED, 0, 2, 24,true,0, true, true,0,"iprmed ", true,
  105.        0x00ffffff, 0x00ffffff};
  106. static reloc_howto_type howto_optcall =
  107.   {  R_OPTCALL, 0,2,24,true,0, true, true, optcall_callback,
  108.        "optcall", true, 0x00ffffff, 0x00ffffff};
  109.  
  110. static reloc_howto_type *
  111. DEFUN (coff_i960_reloc_type_lookup, (abfd, code),
  112.        bfd *abfd AND
  113.        bfd_reloc_code_real_type code)
  114. {
  115.   switch (code)
  116.     {
  117.     default:
  118.       return 0;
  119.     case BFD_RELOC_I960_CALLJ:
  120.       return &howto_optcall;
  121.     case BFD_RELOC_32:
  122.       return &howto_rellong;
  123.     case BFD_RELOC_24_PCREL:
  124.       return &howto_iprmed;
  125.     }
  126. }
  127.  
  128. /* The real code is in coffcode.h */
  129.  
  130. #define RTYPE2HOWTO(cache_ptr, dst) \
  131. {                            \
  132.    reloc_howto_type *howto_ptr;                \
  133.    switch ((dst)->r_type) {                \
  134.      case 17: howto_ptr = &howto_rellong; break;    \
  135.      case 25: howto_ptr = &howto_iprmed; break;        \
  136.      case 27: howto_ptr = &howto_optcall; break;    \
  137.      default: howto_ptr = 0; break;            \
  138.      }                            \
  139.    cache_ptr->howto = howto_ptr;            \
  140.  }
  141.  
  142. #include "coffcode.h"
  143.  
  144. #undef coff_bfd_reloc_type_lookup
  145. #define coff_bfd_reloc_type_lookup coff_i960_reloc_type_lookup
  146.  
  147. bfd_target icoff_little_vec =
  148. {
  149.   "coff-Intel-little",        /* name */
  150.   bfd_target_coff_flavour,
  151.   false,            /* data byte order is little */
  152.   false,            /* header byte order is little */
  153.  
  154.   (HAS_RELOC | EXEC_P |        /* object flags */
  155.    HAS_LINENO | HAS_DEBUG |
  156.    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
  157.  
  158.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  159.   0,                /* leading underscore */
  160.   '/',                /* ar_pad_char */
  161.   15,                /* ar_max_namelen */
  162.  
  163.   3,                /* minimum alignment power */
  164.   _do_getl64, _do_getl_signed_64, _do_putl64,
  165.      _do_getl32, _do_getl_signed_32, _do_putl32,
  166.      _do_getl16, _do_getl_signed_16, _do_putl16, /* data */
  167.   _do_getl64, _do_getl_signed_64, _do_putl64,
  168.      _do_getl32, _do_getl_signed_32, _do_putl32,
  169.      _do_getl16, _do_getl_signed_16, _do_putl16, /* hdrs */
  170.  
  171.  {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  172.    bfd_generic_archive_p, _bfd_dummy_target},
  173.  {bfd_false, coff_mkobject,    /* bfd_set_format */
  174.    _bfd_generic_mkarchive, bfd_false},
  175.  {bfd_false, coff_write_object_contents, /* bfd_write_contents */
  176.    _bfd_write_archive_contents, bfd_false},
  177.   JUMP_TABLE(coff),
  178.   COFF_SWAP_TABLE,
  179. };
  180.  
  181.  
  182. bfd_target icoff_big_vec =
  183. {
  184.   "coff-Intel-big",        /* name */
  185.   bfd_target_coff_flavour,
  186.   false,            /* data byte order is little */
  187.   true,                /* header byte order is big */
  188.  
  189.   (HAS_RELOC | EXEC_P |        /* object flags */
  190.    HAS_LINENO | HAS_DEBUG |
  191.    HAS_SYMS | HAS_LOCALS | DYNAMIC | WP_TEXT),
  192.  
  193.   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
  194.   0,                /* leading underscore */
  195.   '/',                /* ar_pad_char */
  196.   15,                /* ar_max_namelen */
  197.  
  198.   3,                /* minimum alignment power */
  199. _do_getl64, _do_getl_signed_64, _do_putl64,
  200.      _do_getl32, _do_getl_signed_32, _do_putl32,
  201.      _do_getl16, _do_getl_signed_16, _do_putl16, /* data */
  202. _do_getb64, _do_getb_signed_64, _do_putb64,
  203.      _do_getb32, _do_getb_signed_32, _do_putb32,
  204.      _do_getb16, _do_getb_signed_16, _do_putb16, /* hdrs */
  205.  
  206.   {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
  207.      bfd_generic_archive_p, _bfd_dummy_target},
  208.   {bfd_false, coff_mkobject,    /* bfd_set_format */
  209.      _bfd_generic_mkarchive, bfd_false},
  210.   {bfd_false, coff_write_object_contents,    /* bfd_write_contents */
  211.      _bfd_write_archive_contents, bfd_false},
  212.   JUMP_TABLE(coff),
  213.   COFF_SWAP_TABLE,
  214. };
  215.